package com.tdam2011.grupo03.common;

import android.text.InputFilter;
import android.text.InputType;
import android.text.Spanned;
import android.text.method.NumberKeyListener;

public class InputFilterManager {

	public static InputFilter[] getDateFilter() {
		InputFilter[] filter = new InputFilter[1];
		filter[0] = new InputFilter() {
			@Override
			public CharSequence filter(CharSequence source, int start, int end,
					Spanned dest, int dstart, int dend) {
				for (int i = start; i < end; i++) {
					if (!Character.isDigit(source.charAt(i))
							|| dest.length() > 9)
						return "";
					if (dest.length() == 2 || dest.length() == 5)
						return "/" + source;
				}
				return null;
			}
		};
		return filter;
	}

	public static NumberKeyListener getInputTypeNumberListener() {
		NumberKeyListener keyListener = new NumberKeyListener() {
			public int getInputType() {
				return InputType.TYPE_CLASS_NUMBER;
			}

			@Override
			protected char[] getAcceptedChars() {
				return new char[] { '0', '1', '2', '3', '4', '5', '6', '7',
						'8', '9', '/' };
			}
		};
		return keyListener;
	}
}
